/*
This file is part of Docking@Home.
http://docking.gcl.cis.udel.edu
Copyright (C) 2009 University of Delaware

Docking@Home is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Docking@Home is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Docking@Home.  If not, see <http://www.gnu.org/licenses/>.
*/
/*
	Filename: Ligand.cpp
	Description: A biological model that represents a ligand
	Revision History: 
		Created - 12/04/08
	Author: Robert Keller (12/04/08 -> Current)
*/

#include "Ligand.h"

// ------------------------------------------------------------
// Constructor / Destructor
// ------------------------------------------------------------

Ligand::Ligand ()
	: DEFAULT_CAMERA_DISTANCE(25.0f),
	  DEFAULT_X_TRANSLATE_VALUE(2.0f),
	  DEFAULT_Y_TRANSLATE_VALUE(2.0f),
	  DEFAULT_Z_TRANSLATE_VALUE(3.0f)
{
	init ("", "");
}// Ligand

Ligand::Ligand (const char pdb[BIOMODEL_MAX_FILNAME_LENGTH],const char psf[BIOMODEL_MAX_FILNAME_LENGTH])
	: DEFAULT_CAMERA_DISTANCE(25.0f),
	  DEFAULT_X_TRANSLATE_VALUE(2.0f),
	  DEFAULT_Y_TRANSLATE_VALUE(2.0f),
	  DEFAULT_Z_TRANSLATE_VALUE(3.0f)
{
	init (pdb, psf);
}// Protein

Ligand::~Ligand ()
{
}// ~Ligand

// ------------------------------------------------------------
// Initialization Functions
// ------------------------------------------------------------

void Ligand::init (const char pdb[BIOMODEL_MAX_FILNAME_LENGTH],const char psf[BIOMODEL_MAX_FILNAME_LENGTH])
{
	drawRep = VDW;

	setPDBFilename(pdb);
	setPSFFilename(psf);
}// init

// ------------------------------------------------------------
// Required BioModel Functions
// ------------------------------------------------------------

void Ligand::draw ()
{
	float transformation[16];
	
	if (getNumAtoms() > 1)
	{
		float translation[3] = 
			{translateX, translateY, translateZ};
		float distBetween = getDistanceBetweenFromDrawRep();
	
		glHelper->setViewportProperties(DEFAULT_CAMERA_DISTANCE);

		arcBall.getTransformation(transformation);

		performModelTransformations (distBetween, userRotation, 
			translation, transformation );

		switch (drawRep)
		{
		case VDW:
			drawVDWRep (distBetween);
			break;
		case CPK:
			drawCPKRep (distBetween);
			break;
		case LINE:
			drawLineRep (distBetween);
			break;
		}// switch
	}// if
}// draw

void Ligand::drawMultiple (bool useThisTransformation)
{
	float transformation[16] = {0.0f};

	/*
	if (getNumAtoms() < 1)
		drawNoAtomsText((float)glHelper->getViewportWidth(), 
			(float)glHelper->getViewportHeight());
	*/

	if (useThisTransformation)
	{
		float translation[3] = 
			{translateX, translateY, translateZ};

		glHelper->setViewportProperties(DEFAULT_CAMERA_DISTANCE);
		arcBall.getTransformation(transformation);

		performModelTransformations (DEFAULT_CPK_LENGTH, userRotation, translation, transformation );

		drawCPKRep (DEFAULT_CPK_LENGTH);
	}// if
	else
	{
		float translation[3] = {0.0f};
		drawCPKRep (DEFAULT_MULTIPLE_LENGTH);
	}// else
}// drawMultiple

// ------------------------------------------------------------
// View Changing Functions
// ------------------------------------------------------------

void Ligand::addToTranslateX ()
{
	translateX += DEFAULT_X_TRANSLATE_VALUE;
}// addToTranslateX

void Ligand::addToTranslateY ()
{
	translateY += DEFAULT_Y_TRANSLATE_VALUE;
}// addToTranslateY

void Ligand::addToTranslateZ ()
{
	translateZ += DEFAULT_Z_TRANSLATE_VALUE;
}// addToTranslateZ

void Ligand::subtractFromTranslateX ()
{
	translateX -= DEFAULT_X_TRANSLATE_VALUE;
}// subtractFromTranslateX

void Ligand::subtractFromTranslateY ()
{
	translateY -= DEFAULT_Y_TRANSLATE_VALUE;
}// subtractFromTranslateY

void Ligand::subtractFromTranslateZ ()
{
	translateZ -= DEFAULT_Z_TRANSLATE_VALUE;
}// subtractFromTranslateZ
